import os
import shutil

# 读取记事本内容
with open(r'C:\Users\12107\Desktop\test.txt', 'r') as file:
    lines = file.readlines()

# 去除每行末尾的换行符
lines = [line.strip() for line in lines]

# 原始文件夹路径
source_folder = 'E:\\biaozhipai\\Annotations'

# 目标文件夹路径
destination_folder = 'E:\\destination_folder'

# 遍历每行内容，查找对应的 XML 文件并保存到目标文件夹
for line in lines:
    xml_file = line + '.xml'  # 构建 XML 文件名
    xml_path = os.path.join(source_folder, xml_file)  # XML 文件路径

    if os.path.isfile(xml_path):
        # 创建目标文件夹，如果不存在的话
        os.makedirs(destination_folder, exist_ok=True)

        # 复制 XML 文件到目标文件夹
        destination_path = os.path.join(destination_folder, xml_file)
        shutil.copy(xml_path, destination_path)
    else:
        print(f"XML file '{xml_file}' not found.")

